<template>
	<div class="alarmConfiguration zy-content">
		<search ref="search" :columns="searchData" @getSearch="getSearch(arguments)"></search>
		<div class="list-layout mt16">
			<div class="btns clear">
				<span class="title">{{ $t('common.listInformation') }}</span>
				<Button @click="exportTemplateClick">
					{{ $t('common.batchExport') }}
				</Button>
				<!-- <Button @click="getTableColumns(columns)">{{ handleContextMenuStatus ? $t('显示操作栏') : $t('隐藏操作栏') }}</Button> -->
			</div>
			<div class="tableContent">
				<Table
					class="resizable-table"
					border
					@on-column-width-resize="onColumnWidthResize"
					:columns="columnsList"
					ellipsis
					ref="selection"
					stripe
					:data="dataArr"
					@on-selection-change="onSelectChange"
				></Table>
			</div>
			<div class="pageWrap mt16">
				<pageLeftTitle :total="total" :selected="delIds.length" />
				<Page
					:total="total"
					:page-size="pageSize"
					:page-size-opts="pageSizeOption"
					:current="pageNum"
					@on-change="changePageNum"
					@on-page-size-change="changePageSize"
					show-sizer
					show-total
				/>
			</div>
		</div>
	</div>
</template>

<script>
import search from '@/components/curd/searchList.vue';
import fileDownload from 'js-file-download';
import toggleTableOperation from '@/mixins/toggleTableOperation';
export default {
	name: 'benchmarkActualAnalysis',
	components: { search },
	mixins: [toggleTableOperation],
	data() {
		return {
			loading: false,
			searchParams: {},
			pageNum: 1,
			pageSize: 10,
			total: 0,
			delIds: [],
			searchData: [
				{
					title: '车间',
					key: 'functionalLocation',
					type: 'cascader',
					dicUrl: '/basic/organization/findListByToken?level=0',
					params: {
						label: 'name',
						value: 'code',
						children: 'children',
					},
				},
				{
					title: '工单号',
					key: 'workCode',
				},
				{
					title: '工单组号',
					key: 'groupItem',
				},

				{
					title: '产品编号',
					key: 'productCode',
				},
				{
					title: '产品名称',
					key: 'productName',
				},
				// {
				// 	title: '物料编号',
				// 	key: 'materialCode',
				// },
				// {
				// 	title: '物料名称',
				// 	key: 'materialName',
				// },
				{
					title: '规格型号',
					key: 'materialType',
				},
				{
					title: '生产日期',
					key: 'time',
					type: 'daterange',
          // cascader:'shift'
				},
				{
					title: '班次',
					key: 'shift',
					// type: 'select',
          // dicUrl:'/dms/mobile/getShiftList',
				},
				{
					title: '操作工',
					key: 'operator',
				},
			],
			columns: [
				{
					key: 'selection',
					type: 'selection',
					width: 60,
					align: 'center',
				},
				{
					title: '生产日期',
					key: 'shiftTime',
					minWidth: 130,
					align: 'center',
					resizable: true,
					render: (h, params) => {
						return h('div', this.$moment(params.row.shiftTime).format('YYYY-MM-DD'));
					},
				},
				{
					title: '班次',
					key: 'shift',
					minWidth: 130,
					align: 'center',
					resizable: true,
				},
				{
					title: '车间',
					key: 'functionalLocationName',
					minWidth: 130,
					align: 'center',
					resizable: true,
				},
				{
					title: '工单号',
					key: 'workCode',
					minWidth: 130,
					align: 'center',
					resizable: true,
				},
				{
					title: '工单组号',
					key: 'groupItem',
					minWidth: 130,
					align: 'center',
					resizable: true,
				},
				{
					title: '产品编号',
					key: 'productCode',
					minWidth: 130,
					align: 'center',
					resizable: true,
				},
				{
					title: '产品名称',
					key: 'productName',
					minWidth: 130,
					align: 'center',
					resizable: true,
				},
				{
					title: '设备编号',
					key: 'deviceCode',
					minWidth: 150,
					align: 'center',
					resizable: true,
				},
				{
					title: '模具编号',
					key: 'deviceName',
					minWidth: 150,
					align: 'center',
					resizable: true,
				},
				{
					title: '物料编号',
					key: 'materialCode',
					minWidth: 150,
					align: 'center',
					resizable: true,
				},
				{
					title: '物料名称',
					key: 'materialName',
					minWidth: 150,
					align: 'center',
					resizable: true,
				},
				{
					title: '规格型号',
					key: 'materialType',
					minWidth: 150,
					align: 'center',
					resizable: true,
				},
				{
					title: '产品净重',
					key: 'weight',
					minWidth: 150,
					align: 'center',
					resizable: true,
				},
				
				{
					title: '投料总数',
					key: 'feedingSum',
					minWidth: 150,
					align: 'center',
					resizable: true,
				},
				{
					title: '提报合格数量',
					key: 'reportingQualifiedQuantity',
					minWidth: 150,
					align: 'center',
					resizable: true,
				},
				{
					title: '基础单位',
					key: 'basicUnit',
					minWidth: 150,
					align: 'center',
					resizable: true,
				},
				{
					title: '提报合格重量',
					key: 'reportingQualifiedWeight',
					minWidth: 150,
					align: 'center',
					resizable: true,
				},
				{
					title: '报废数量',
					key: 'scrapQuantity',
					minWidth: 150,
					align: 'center',
					resizable: true,
				},
				{
					title: '报废重量',
					key: 'scrapWeight',
					minWidth: 150,
					align: 'center',
					resizable: true,
				},
				{
					title: '调模损耗',
					key: 'lossStatistics',
					minWidth: 150,
					align: 'center',
					resizable: true,
				},
				{
					title: '料头料尾重量',
					key: 'materialHeadWeight',
					minWidth: 150,
					align: 'center',
					resizable: true,
				},
				{
					title: '操作工',
					key: 'operator',
					minWidth: 150,
					align: 'center',
					resizable: true,
				},
			],
			dataArr: [],
			pageSizeOption: [10, 20, 30, 40],
		};
	},
	mounted() {
		this.getTableColumnsWidth(this.columns);
		this.$refs.search.getSearch();
	},
	methods: {
		getSearch(arg) {
			this.searchParams = JSON.parse(JSON.stringify(arg[0]));
			const { time } = this.searchParams;
			if (time && time.length > 0) {
				this.searchParams.startShiftTime = time[0];
				this.searchParams.endShiftTime = time[1];
			}
			delete this.searchParams.time;
		
			this.pageNum = 1;
			this.searchList();
		},
		reset() {
			this.searchParams = {};
			this.changeNum();
		},
		//分页
		changeNum() {
			this.pageNum = 1;
			this.searchList();
		},
		changePageSize(pageSize) {
			this.pageSize = pageSize;
			this.searchList();
		},

		changePageNum(val) {
			this.pageNum = val;
			this.searchList();
		},
		//查询列表
		searchList() {
			let params = {
				pageNum: this.pageNum,
				pageSize: this.pageSize,
				...this.searchParams,
			};
			this.axios({
				method: 'post',
				url: '/dms/pRoductionReporting/queryLossStatisticsReportList',
				data: params,
			}).then((res) => {
				if (res.code === 200) {
					this.dataArr = res.data.records;
					this.total = res.data.total;
				} else {
					this.$Message.warning({
						content: res.msg,
						duration: 6,
						closable: true,
					});
				}
			});
		},
		//勾选列表
		onSelectChange(selection) {
			let myArray = [];
			selection.map((item, index) => {
				myArray.push(item.id);
			});
			this.delIds = myArray;
			if (selection.length > 0) {
				this.allCheck = true;
			} else {
				this.allCheck = false;
			}
		},
		//导出
		exportTemplateClick() {
			let params = {
				delIds: this.delIds,
			};
			for (let key in this.searchParams) {
				if (this.searchParams[key]) {
					this.$set(params, key, this.searchParams[key]);
				}
			}
			const filName = '工单生产日报表';
			this.axios({
				url: '/dms/oee-board/workProductionDailyReport/export',
				method: 'post',
				data: params,
			}).then((res) => {
				if (res.code !== 555) {
					this.axios({
						url: '/dms/oee-board/workProductionDailyReport/export',
						method: 'post',
						responseType: 'blob',
						data: params,
					}).then((res1) => {
						fileDownload(res1, filName + '.xls');
					});
				} else {
					this.$Message.warning(res.msg);
				}
			});
		},
	},
};
</script>

<style scoped lang="scss">
.ivu-input-number {
	width: -webkit-fill-available;
}

.row_click {
	cursor: pointer;
	color: rgb(50, 113, 240) !important;
}
</style>
